package org.come.npc;

import org.come.Frame.RaceChangeMainJframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.RaceChangeMainJpanel;
import org.come.action.NpcMenuAction;
import org.come.until.CutButtonImage;
import org.come.until.FormsManagement;

import com.tool.ModerateTask.Hero;
import com.tool.image.ImageMixDeal;

public class RoleConversion implements NpcMenuAction {

	@Override
	public void menuControl(String type) {

		if ("我想转换种族".equals(type)) {
			roleTrans();
		} else if ("我已做好了转生准备".equals(type)) {
			roleTurnaround();
		}

	}
	/** 种族转换 */
	public void roleTrans() {
		// 判断是否是组队状态
		if (ImageMixDeal.userimg.getRoleShow().getTroop_id() != null) {
			ZhuFrame.getZhuJpanel().addPrompt("您正在组队中，不能转换种族！！！");
			return;
		}
		// 判断是否在交易中
		if (FormsManagement.getframe(14).isVisible()) {
			ZhuFrame.getZhuJpanel().addPrompt("您正在交易中，不能转换种族！！！");
			return;
		}
		int number = 6;
		// 先判断人物的等级，看是否转生条件成熟
		if (ImageMixDeal.userimg.getRoleShow().getGrade() > 102 && ImageMixDeal.userimg.getRoleShow().getGrade() <= 338) {
			number = 8;
		} else if (ImageMixDeal.userimg.getRoleShow().getGrade() > 338&&ImageMixDeal.userimg.getRoleShow().getGrade() <= 459) {
			number = 10;
		}else if (ImageMixDeal.userimg.getRoleShow().getGrade() > 459) {
			number = 12;
		}
		RaceChangeMainJpanel raceChangeMainJpanel = RaceChangeMainJframe.getRaceChangeMainJframe().getRaceChangeMainJpanel();
		raceChangeMainJpanel.setNumber(number);
		for (int i = 0; i < raceChangeMainJpanel.getSexBtn().length; i++) {
			raceChangeMainJpanel.getSexBtn()[i].setIcon(i == 0 ? CutButtonImage.getImage("skin/8100226/button/101.png", 7, 7) : null);
		}
		raceChangeMainJpanel.reloadRace(raceChangeMainJpanel.getRoleType(), raceChangeMainJpanel.getNumber());
		raceChangeMainJpanel.setLeixing(0);
		raceChangeMainJpanel.setSpecies_id(null);
		// // 显示出来种族转换的界面
		FormsManagement.showForm(41);
	}

	/** 人物转生 */
	public void roleTurnaround() {
		// 判断是否是组队状态
		if (ImageMixDeal.userimg.getRoleShow().getTroop_id() != null) {
			ZhuFrame.getZhuJpanel().addPrompt("您正在组队中，不能转生！！！");
			return;
		}
		// 判断是否在交易中
		if (FormsManagement.getframe(14).isVisible()) {
			ZhuFrame.getZhuJpanel().addPrompt("您正在交易中，不能转生！！！");
			return;
		}
		// // 先判断自己是否还有任务
		if (Hero.getHero().getDoingTasks().size() != 0) {// 还有任务
			ZhuFrame.getZhuJpanel().addPrompt("你还有未完成的任务，不可转生！");
			return;
		}
		boolean bool = false;// 用来判断角色是否够等级转生
		int number = 8;
		// 先判断人物的等级，看是否转生条件成熟
		if (ImageMixDeal.userimg.getRoleShow().getGrade() <= 102) {
			if (ImageMixDeal.userimg.getRoleShow().getGrade() == 102) {
				bool = true;
				number = 8;
			}
		} else if (ImageMixDeal.userimg.getRoleShow().getGrade() <= 210) {
			if (ImageMixDeal.userimg.getRoleShow().getGrade() == 210) {
				bool = true;
				number = 8;
			}
		} else if (ImageMixDeal.userimg.getRoleShow().getGrade() <= 338) {
			if (ImageMixDeal.userimg.getRoleShow().getGrade() == 338) {
				bool = true;
				number = 10;
			}
		} else if (ImageMixDeal.userimg.getRoleShow().getGrade() <= 459) {
			if (ImageMixDeal.userimg.getRoleShow().getGrade() == 459) {
				bool = true;
				number = 12;
			}
		}
		if (bool) {// 等级足够
			RaceChangeMainJpanel raceChangeMainJpanel = RaceChangeMainJframe.getRaceChangeMainJframe().getRaceChangeMainJpanel();
			raceChangeMainJpanel.setNumber(number);
			for (int i = 0; i < raceChangeMainJpanel.getSexBtn().length; i++) {
				raceChangeMainJpanel.getSexBtn()[i].setIcon(i == 0 ? CutButtonImage.getImage("skin/8100226/button/101.png", 7, 7) : null);
			}
			raceChangeMainJpanel.reloadRace(raceChangeMainJpanel.getRoleType(), number);
			raceChangeMainJpanel.setLeixing(1);
			raceChangeMainJpanel.setSpecies_id(null);
			// 显示出来种族转换的界面
			FormsManagement.showForm(41);
		} else {// 等级不足够
			ZhuFrame.getZhuJpanel().addPrompt("你还不具备转生的条件！");
		}
	}

//	/** 判断是否是可以转生的种族 */
//	public boolean okOrNo() {
//		if (ZhuJpanel.getSpecies_id().compareTo(new BigDecimal(20009)) != 0 && ZhuJpanel.getSpecies_id().compareTo(new BigDecimal(20010)) != 0
//				&& ZhuJpanel.getSpecies_id().compareTo(new BigDecimal(21009)) != 0 && ZhuJpanel.getSpecies_id().compareTo(new BigDecimal(21010)) != 0
//				&& ZhuJpanel.getSpecies_id().compareTo(new BigDecimal(22009)) != 0 && ZhuJpanel.getSpecies_id().compareTo(new BigDecimal(22010)) != 0) {
//			return true;
//		}
//		return false;
//	}
}
